<template>
    <ui-main>
        <!-- <div slot="header">
            <mt-header title="法律法规">
                <mt-button slot="left" icon=back @click="$router.go(-1)"></mt-button>
            </mt-header>
        </div> -->

     
        <van-search v-model="searchVal" placeholder="请输入搜索关键词"   @search="onSearch" />

        <van-cell @click.native="goDetail(item)" is-link :title="item.name" v-for="(item,index) in showList" :key="index">
        </van-cell>
    </ui-main>
</template>

<script>
    export default {
        data() {
            return {
                showList: [],
                tempList: [],
                searchVal: ''
            }
        },
        mounted() {
            this.$title('法律法规');
            this.getLaws();
        },
        methods: {
            goDetail(item) {
                this.$router.push({
                    path: 'faguimingxi',
                    query: {
                        id: item.id
                    }
                })
            },
            onSearch(v) {
                console.log(v);
                if(this.$isBlank(v)) {
                    this.showList = this.tempList;
                    return;
                }
                var showData = []
                for (let index = 0; index < this.tempList.length; index++) {
                    const element = this.tempList[index];
                    if ((element.name && element.name.indexOf(v) > -1) ||
                        (element.key_word && element.key_word.indexOf(v) > -1) ||
                        (element.industry_name && element.industry_name.indexOf(v) > -1)) {
                        showData.push(element)
                    }
                }
                this.showList = showData
            },

    

            getLaws() {
                this.$loading.open()
                this.$http.post('/hidden/lawfiles/table', {}).then(({
                    data
                }) => {
                    this.$loading.close();
                    if (this.$isNotBlank(data) && this.$isArray(data.content)) {
                        this.showList = data.content
                        this.tempList = data.content
                    }
                }).catch(() => {
                    this.$loading.close();
                })
            }
        }
    }

</script>
